const mockData = require('../../utils/data.js')

Page({
  data: {
    destination: null,
    categories: [],
    hotProducts: [],
    flashSaleProducts: [],
    groupBuyProducts: [],
    bargainProducts: [],
    selectedCategory: 'all'
  },
  
  onLoad(options) {
    const id = parseInt(options.id) || 1
    this.loadDestination(id)
  },
  
  loadDestination(id) {
    const destination = mockData.destinations[id] || {
      id: 1,
      name: '北京',
      image: '',
      categories: mockData.destinations[1].categories
    }
    
    // 加载产品
    const products = mockData.products
    
    this.setData({
      destination,
      categories: destination.categories,
      hotProducts: products.slice(0, 3),
      flashSaleProducts: products.filter(p => p.type === 'flash-sale'),
      groupBuyProducts: products.filter(p => p.type === 'group-buy'),
      bargainProducts: products.filter(p => p.type === 'bargain')
    })
    
    wx.setNavigationBarTitle({
      title: destination.name
    })
  },
  
  selectCategory(e) {
    const category = e.currentTarget.dataset.category
    this.setData({
      selectedCategory: category
    })
  },
  
  goToProductDetail(e) {
    const id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: `/pages/product-detail/product-detail?id=${id}`
    })
  },
  
  goToLocalProductList(e) {
    const category = e.currentTarget.dataset.category
    wx.navigateTo({
      url: `/pages/local-product-list/local-product-list?destinationId=${this.data.destination.id}&category=${category}`
    })
  }
})

